package com.leizi.igym.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leizi.igym.domain.TrainerCategory;
import com.leizi.igym.service.TrainerCategoryService;
import com.leizi.igym.mapper.TrainerCategoryMapper;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
* @author PC
* @description 针对表【t_trainer_category】的数据库操作Service实现
* @createDate 2024-04-07 10:01:24
*/
@Service
public class TrainerCategoryServiceImpl extends ServiceImpl<TrainerCategoryMapper, TrainerCategory>
    implements TrainerCategoryService{

    @Override
    public List<Long> getTrainerByCategory(Long categoryId) {
        if (Objects.isNull(categoryId) || categoryId < 0){
            return Collections.emptyList();
        }
        QueryWrapper<TrainerCategory> qw = new QueryWrapper<>();
        qw.eq("category_id",categoryId);
        List<TrainerCategory> list = this.getBaseMapper().selectList(qw);
        if (CollectionUtil.isEmpty(list)){
            return Collections.emptyList();
        }
        // System.out.println("list = " + list);
        return list.stream().map(trainerCategory -> trainerCategory.getTrainerId()).toList();
    }
}




